package com.sangmo.boot.auth.core;

import com.sangmo.boot.auth.core.interfaces.GrantCodeRequest;
import com.sangmo.boot.auth.core.interfaces.GrantTokenRequest;
import com.sangmo.boot.auth.core.interfaces.GrantTokenResponse;
import com.sangmo.boot.auth.core.interfaces.ValidateTokenRequest;
import com.sangmo.boot.framework.common.session.UserSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AuthorizeService {
    @Autowired private AccessTokenService accessTokenService;
    @Autowired private AuthorizeCodeService authorizeCodeService;

    public GrantTokenResponse grant(GrantTokenRequest req) {
        return accessTokenService.grant(req);
    }

    public UserSession.Authorize<?> validate(ValidateTokenRequest req) {
        return accessTokenService.validate(req);
    }

    public void gainCode(GrantCodeRequest req) {
        authorizeCodeService.grant(req);
    }

    public void logout(String token) {
        accessTokenService.delete(token);
    }
}
